function loadPageCandidato() {
	var ajaxResp = ajaxJSONtoPOST(Object.toJSON({process : "combos"}), serviceDemand);
	if(ajaxResp.Flag=="true") {
		var htmlCode = ajaxResp.HTMLCode;
		/*
		alert(htmlCode.split("~")[0]);
		alert(htmlCode.split("~")[1]);
		alert(htmlCode.split("~")[1]);
		*/
		$("#cadPhone_1 .lbl").html(htmlCode.split("~")[0]);
		
		$("#cadMail_1 .lbl").html(htmlCode.split("~")[1]);
		
		$("#cadTech_1 .lbl").html(htmlCode.split("~")[2]);
	}
}

function saveCandidate() {
		var t =  $("#newCandidateID").val()==""?1:3;
		var editMode = (t==3);
		var caName	= $("#caiName_1").val();
		var caPat 	= $("#caiPatname_1").val();
		var caMat 	= $("#caiMatname_1").val();
		var caFuente= $("#caiSource_1").val();
		var caSkill = $("#caiSkill_1").val();
		
		var chPh = $("#cadPhone").children();
		arrayPhone = getDataChilds(chPh);
		
		var chMl = $("#cadMail").children();
		arrayMail = getDataChilds(chMl);
		
		var chTc = $("#cadTech").children();
		arrayTech = getDataChilds(chTc);
		
		//alert(caName+"|"+caPat+"|"+caMat+"|"+caFuente+"|"+caMail+"|"+caSkill+"|"+caTel+"|"+caMov);
		var dataIncomplete = new Array(); 
		if(!validateFields(caName, 1))	{dataIncomplete.push("Nombre"); 			}
		if(!validateFields(caPat, 1))	{dataIncomplete.push("Apellido Paterno"); 	}
		if(!validateFields(caMat, 1))	{dataIncomplete.push("Apellido Materno");	}
		if(!validateFields(caFuente, 1)){dataIncomplete.push("Fuente"); 			}
		if(!validateFields(caSkill, 1))	{dataIncomplete.push("Skill"); 				}
		
		if(dataIncomplete.length==0) {
			
			var jsonReq = {
					process : "cCandidate",
					type 	: t,
					name 	: caName,
					ap 		: caPat,
					am 		: caMat,
					cf 		: caFuente,
					cs 		: caSkill,
					telefono: arrayPhone,
					mail	: arrayMail,
					tech	: arrayTech,
					cv		: "",
					id		: $("#newCandidateID").val()=="" ? 0 : $("#newCandidateID").val(),
					cc		: "",
					st		: ""
			};
			
			//alert(Object.toJSON(jsonReq));
			
			var jsonResp = ajaxJSONtoPOST(Object.toJSON(jsonReq), serviceRecruitment);
			if(jsonResp.Flag=="true") {
				$("#newCandidateID").val(jsonResp.idGenerated);
				showEntitiesCandidate(jsonResp.HTMLCode);
				if(editMode) {
					alert("Candidato actualizado correctamente");
				} else {
					alert("Candidato creado correctamente");
				}
			} else {
				alert("Error al crear el Candidato");
			}
			
		} else {
			var msg = "";
			for(var idx=0; idx<dataIncomplete.length; idx++) {
				if(idx == dataIncomplete.length-1){
					if(dataIncomplete[idx]!="") {
						msg+=dataIncomplete[idx]+"";
					}
				} else
					if(dataIncomplete[idx]!="") {
					msg+=dataIncomplete[idx]+", ";
				}
			}
			alert("Favor de llenar los campos faltantes: "+msg);
		}
	}

function showEntitiesCandidate(htmlCode) {
	
	/*
	alert(htmlCode.split("~")[0]);
	alert(htmlCode.split("~")[1]);
	alert(htmlCode.split("~")[2]);
	*/
	
	$("#cadPhone").html(htmlCode.split("~")[0]);
	$("#cadMail").html(htmlCode.split("~")[1]);
	$("#cadTech").html(htmlCode.split("~")[2]);
	
	var arrayParents = new Array();
	arrayParents.push("cadPhone");
	arrayParents.push("cadMail");
	arrayParents.push("cadTech");
	
	showByParents(arrayParents);
}

function editContact(idCandidate) {
	$("#newCandidateID").val(idCandidate);
	showCandidate(idCandidate);
}

function showCandidate(idCandidate) {
	var jsonReq = {
			process : "sCandidate",
			type : 2,
			ap 	 : "",
			am   : "",
			st	 : "",
			cc   : "",
			cf   : "",
			cs   : "",
			id	 : idCandidate,
			
			name 	: "",
			telefono: new Array(),
			mail	: new Array(),
			tech	: new Array(),
			cv		: ""
	};
	//alert(Object.toJSON(jsonReq));
	var jsonResp = ajaxJSONtoPOST(Object.toJSON(jsonReq), serviceRecruitment);
	if(jsonResp.Flag=="true") {
	 	$("#caiName_1").val(jsonResp.candidate.nombreCandidato);
		$("#caiPatname_1").val(jsonResp.candidate.apellidoPaterno);
		$("#caiMatname_1").val(jsonResp.candidate.apellidoMaterno);
		$("#caiSource_1").val(jsonResp.candidate.fuente);
		$("#caiSkill_1").val(jsonResp.candidate.skill);
		showEntitiesCandidate(jsonResp.HTMLCode);
		loadCatalogCandidatesTab(0);
	} else {
		alert("Error al mostrar el Candidato seleccionado");
	}
}